package cn.hqm.hqmtechnology.config;

import cn.hqm.hqmtechnology.filters.interceptor.TokenFilterInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {

    @Resource
    private TokenFilterInterceptor tokenFilterInterceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") //处理的请求地址
                .allowedMethods ("*")
                .allowedOrigins("*")
                .allowedHeaders ("*")
                .allowCredentials (false)
                .exposedHeaders ("")
                .maxAge (3600) ;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器并指定拦截路径
        registry.addInterceptor(tokenFilterInterceptor).addPathPatterns("/**");
    }
}